<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>b</title>
  <!-- 引入Vue -->
  <script type="text/javascript" src="../../js/vue.js"></script>
</head>

<body>
  <!-- 准备好一个容器-->
  <div id="demo">
    <h2>今天的天气{{text}}</h2>
    <img width="100" :src="url"><br>
    <button @click="chang">确定</button>
  </div>
</body>

<script type="text/javascript">
  // 创建Vue实例
  var vm = new Vue({
    el: '#demo',
    data() {
      return {
        isHos: true,
        url: 'http://49.232.112.44/images/hot.jpg'
      }
    },
    computed: {
      text() {
        return this.isHos ? '晴天' : '雨天'
      }
    },
    methods: {
      chang() {
        this.isHos = !this.isHos;
      }
    },
    watch: {
      isHot: {
        immediate: true, // 立即执行
        handler(newValue) {
          if (newValue === '晴天') {
            this.url = 'http://49.232.112.44/images/hot.jpg'
          } else {
            this.url = 'http://49.232.112.44/images/cool.jpg'
          }
        }
      }
    }
  })
</script>

</html>